

use "${data}ACS2017-2021_finalready.dta" , clear 


		
	*KEEP M/RRIED MIGRANTS BEFORE MIGRATION 
	
	keep if status_evermarried ==1
	
	foreach v in evermarr_det1 evermarr_det2 evermarr_det3  {
		g STD_`v'= `v'	
	}
	* 
	
************************************************************************************************************************			
*  FIGURE 2, PANEL A			
************************************************************************************************************************			
	* MALE
preserve 
	keep if male==1 
	keep if yrsusa1<21 
	collapse (mean) evermarr_det1 evermarr_det2 evermarr_det3 (semean) STD_*  , by(yrsusa1)
	
	foreach v in evermarr_det1 evermarr_det2 evermarr_det3  {
		g upper_`v'= `v' + 1.96*STD_`v'
		g lower_`v'= `v' - 1.96*STD_`v'	
	}
							
twoway  ( rarea   upper_evermarr_det2 lower_evermarr_det2     yrsusa1 ,    color(gs15)  ) || /// 
		( rarea   upper_evermarr_det3 lower_evermarr_det3     yrsusa1 ,    color(gs15)  ) || ///  
		(line   evermarr_det2   yrsusa1 , lcolor(black) lpattern(dash) ) ///
	      (line  evermarr_det3   yrsusa1 , lcolor(gs11) ) ///
         , legend(order(3 "Spouse absent" 4   "Separated or divorced") region(lwidth(none)) ) ///
		    xtitle("Years in the US")  ytitle("")   ylab(, angle(horizontal)) graphregion(color(white)) ///
				name(fig2_A, replace) 
	
	graph export "${result}Fig2_panelA.eps",  replace 

	
restore


 
************************************************************************************************************************			
*  FIGURE 2, PANEL B			
************************************************************************************************************************			
	* FEMALE
preserve 
	keep if male==0 
	keep if yrsusa1<21 
	collapse (mean) evermarr_det1 evermarr_det2 evermarr_det3 (semean) STD_*  , by(yrsusa1)
	
	foreach v in evermarr_det1 evermarr_det2 evermarr_det3  {
		g upper_`v'= `v' + 1.96*STD_`v'
		g lower_`v'= `v' - 1.96*STD_`v'	
	}
	
twoway  ( rarea   upper_evermarr_det2 lower_evermarr_det2     yrsusa1 ,   color(gs15)  ) || /// 
		( rarea   upper_evermarr_det3 lower_evermarr_det3     yrsusa1 ,    color(gs15)  ) || ///  
		(line   evermarr_det2   yrsusa1 , lcolor(black) lpattern(dash)   ) ///
	      (line  evermarr_det3   yrsusa1 , lcolor(gs11)  ) ///
         , legend(order(3 "Spouse absent" 4   "Separated or divorced") region(lwidth(none)) ) ///
		    xtitle("Years in the US")  ytitle("")   ylab(, angle(horizontal)) graphregion(color(white)) 	name(fig2_B, replace) 

  graph export "${result}Fig2_panelB.eps",  replace 

				
restore 
		
	

	
************************************************************************************************************************			
*  FIGURE B.2	
************************************************************************************************************************			

		
*** MEXICAN MALE 


	* MALE
preserve 
	keep if male==1 & country_ori==1
	ta country_ori 
	keep if yrsusa1<21 
	
	collapse (mean) evermarr_det1 evermarr_det2 evermarr_det3 (semean) STD_*  , by(yrsusa1)
	
	foreach v in evermarr_det1 evermarr_det2 evermarr_det3  {
		g upper_`v'= `v' + 1.96*STD_`v'
		g lower_`v'= `v' - 1.96*STD_`v'	
	}
							
twoway  ( rarea   upper_evermarr_det2 lower_evermarr_det2     yrsusa1 ,    color(gs15)   ) || /// 
		( rarea   upper_evermarr_det3 lower_evermarr_det3     yrsusa1 ,    color(gs15)   ) || ///  
		(line   evermarr_det2   yrsusa1 , lcolor(black) lpattern(dash)  ) ///
	      (line  evermarr_det3   yrsusa1 , lcolor(gs11) ) ///
         , legend(order(3 "Spouse absent" 4   "Separated or divorced") region(lwidth(none)) ) ///
	xtitle("Years in the US")  ytitle("")   ylab(, angle(horizontal)) graphregion(color(white))  name(figB2, replace) 

  graph export "${result}FigB2.eps",  replace 

	
restore 
		
			
	
			
			